#version 450 compatibility







#define M_PI 3.1415926535897
#define M_2PI 6.2831853071795

//#define FLT_MAX         3.402823466e+38F
//#define FLT_MIN         1.175494351e-38F


struct S_WavesInfos {
    uint    m_Frequency;    //频率
    float   m_Intensity;    //强度
    int     m_WaveOffset;   //波形偏移
    uint    m_WavesEnable;   //波形偏移

};



layout(local_size_x = 2, local_size_y = 1, local_size_z = 1) in;

/*layout( binding = 0 ) uniform Buf_LoalParameter0 {
    uint m_Second;
    uint m_TrackNum;
    uint m_Sampling;
    float m_Gain;
};

layout( binding = 1 ) buffer Buf_LoalParameter1 {
    S_WavesInfos  m_Waves[];
};*/

layout( binding = 2 ) buffer Buf_LoalParameter2 {
    uint m_WaveBaking[];
};


shared uint bakingWave = 0;
void main(){
    
    //uint globalID = ((gl_WorkGroupID.y * gl_NumWorkGroups.x)+ gl_WorkGroupID.x) ;
    //uint localID = globalID * 2 + gl_LocalInvocationID.x;
    m_WaveBaking[gl_WorkGroupID.x] = gl_WorkGroupID.x; 
    /*if(localID >= m_Sampling*m_Second) return;


    float sp = 0.0;
    for (uint i=0; i<m_TrackNum; ++i) {
        if(m_Waves[i].m_WavesEnable == 0) continue;

        float tmp_sp = M_2PI / (float(m_Sampling) / float(m_Waves[i].m_Frequency));
        float offset = m_Waves[i].m_WaveOffset + localID;
        sp += sin(tmp_sp * offset) * m_Waves[i].m_Intensity;
    }

    bakingWave |= int(32767 / abs(sp*m_Gain) * sign(sp))<<(gl_LocalInvocationID.x*16);

    //barrier();
    if(gl_LocalInvocationID.x == 0){
        m_WaveBaking[globalID] = bakingWave;
    }*/
    
}






